﻿using System;
using System.Collections.Generic;
using DomainModel;
using Repository.Abstract;

namespace Repository.NHibernate
{
    public class LessonRepository : Repository<Lesson>, ILessonRepository
    {
        public IEnumerable<Lesson> GetByDateAndTimetable(DateTime date, Timetable timetable)
        {
            using (Session)
            {
                return Session.QueryOver<Lesson>().Where(l => l.Date == date && l.Timetable == timetable).List<Lesson>();
            }
        }

        public IEnumerable<Lesson> GetByTimetable(Timetable timetable)
        {
            using (Session)
            {
                return Session.QueryOver<Lesson>().Where(l => l.Timetable == timetable).List<Lesson>();
            }
        }

        public IEnumerable<Lesson> GetByStudent(User student)
        {
            using (Session)
            {
                return
                    Session.QueryOver<Lesson>().Where(l => l.Timetable.Group == student.Group && l.Timetable.Subgroup == student.Subgroup).List<Lesson>();
            }
        }

        public Lesson GetByStudentAndDate(User student, DateTime date)
        {
            using (Session)
            {
                return Session.QueryOver<Lesson>().Where(l => l.Timetable.Group == student.Group && l.Timetable.Subgroup == student.Subgroup && l.Date == date).SingleOrDefault();
            }
        }
    }
}